<template>
	<view>
		<goodslist :GoodsList="GoodsList"></goodslist>
	</view>
</template>

<script>
import goodslist from '../../components/goodslist/goodslist.vue'
	export default {
		data() {
			return {
				pgge:1,
				GoodsList:[]
			}
		},
		onLoad() {
			// console.log(11)
		  this.getgoodslist()
		},
		//下拉刷新事件
		onReachBottom(){
			if(this.GoodsList < this.pgge * 12) return
			this.pgge++
			this.getgoodslist()
		},
		//上拉刷新事件
		onPullDownRefresh(){
			this.pgge = 1
			this.getgoodslist(()=>{
				uni.stopPullDownRefresh()
				uni.showToast({
					
				    title:'刷新成功'
				});
			})
		},
		methods: {
	     //獲取數據
		async getgoodslist(stopPull){
			 let {data:res} = await this.$http.goodsgetlist({
				 pagenum:this.pgge,
				 pagesize:12
			 })
			 this.pgge  = Number(res.message.pagenum) 
			 res.message.goods.forEach(item =>{
				 item.cat_icon = item.goods_big_logo,
				 item.cat_level = item.goods_price - item.goods_number,
				 item.cat_pid = item.goods_price,
				 item.cat_name = item.goods_name
			 })
			 this.GoodsList = [...this.GoodsList,...res.message.goods]
			 stopPull && stopPull()
		 },
		}
	}
</script>

<style>

</style>
